package br.com.gsc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import br.com.gsc.model.tableMapping.Company;
import br.com.gsc.repository.objRepos.CompanyRepository;
import br.com.gsc.repository.objRepos.ProductRepository;


@Controller
@RequestMapping("/empresa/**")
public class CompanyController {

	@Autowired
	ProductRepository pRepo;
	
	@Autowired
	CompanyRepository cRepo;
	
	@RequestMapping(value="/empresa/{empresaID}",method = RequestMethod.GET)
	public ModelAndView getEmpresa(@PathVariable("empresaID") long id){
		ModelAndView model = new ModelAndView("empresa");
		Company comp = cRepo.findTCompanyByID(id);
		model.addObject("companyId",comp.getId());
		model.addObject("products",comp.getListOfProducts());	
		return model;	
	}
}
